package com.stox.ui.javafx.core.application;

import java.util.Locale;

import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import org.controlsfx.control.PopOver;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.core.widget.SearchTextField;

@Component
@Lazy(true)
public class ApplicationPopOver extends PopOver implements InitializingBean{

	private TabPane tabPane = new TabPane();
	
	@Autowired
	private MyApplicationsTab myApplicationsTab;
	
	@Autowired
	private ApplicationStoreTab applicationStoreTab;
	
	@Autowired
	private BetaApplicationTab betaApplicationTab;
	
	@Autowired
	private SearchTextField applicationSearchTextField;
	
	public ApplicationPopOver() {
		setId("apps-pop-over");
		tabPane.setId("apps-tab-pane");
		setAutoFix(true);
		setAutoHide(true);
		setHideOnEscape(true);
		setArrowLocation(ArrowLocation.TOP_LEFT);
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		tabPane.getTabs().addAll(myApplicationsTab, applicationStoreTab, betaApplicationTab);
		
		Pane pane = new HBox(applicationSearchTextField);
		pane.setId("apps-search-pane");
		HBox.setHgrow(applicationSearchTextField, Priority.ALWAYS);
		
		VBox vBox = new VBox(tabPane, pane);
		vBox.setSpacing(10);
		setContentNode(vBox);
	}
	
	@Autowired
	public void setMessageSource(MessageSource messageSource) {
		setDetachedTitle(messageSource.getMessage("Apps", null, Locale.getDefault()));
	}
	
}
